<%@ page language="java" pageEncoding="UTF-8"%>

<%@page import="com.trw.trp.bean.UserBean,org.apache.commons.lang.StringEscapeUtils"%>
<%@page import="com.trw.trp.util.*" %>
<%@page import="com.trw.trp.bean.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="extjs/ext-all.js.gzjs"></script>
<script type="text/javascript" src="extjs/thirdpart/JSON.js"></script>
<script type="text/javascript" src="js/trp.js"></script>
<link href="extjs/resources/css/ext-all.css" rel="stylesheet"
	type="text/css" />
<link href="css/trp.css" rel="stylesheet" type="text/css" />

<style type="text/css">
.x-btn-default-toolbar-small .x-btn-inner {
	font-size: 13px;
}
</style>
<title>Test Request Platform</title>
</head>
<%
int step=-1;
UserBean cUser = (UserBean)TRPUtil.getFromSession(TRPConstants.CURRENT_USER);
//long userId = user.getUserId();
%>
<body>

<table align="center" cellpadding="0" cellspacing="0" width="100%" height="100%"
	border="0">
	<tr id="toolbarDiv">
		<td width="20%" height=50 style="font-size:20px">Welcome:  <%= session.getAttribute("currentUser")==null?"":((UserBean)session.getAttribute("currentUser")).getName() %></td>
		<td align="center" width=700>
			<table width="100%" height="100%" id="statusTable" style="display:none">
				<tr valign="middle">
					<td width=70>General Information</td><td width=20 style='background-color:gray;'><hr></td>
					<td width=70>Technical Information</td><td width=20 style='background-color:gray;'><hr></td>
					<!--td width=70>Sample & Fixture Information</td><td width=20 style='background-color:gray;'><hr></td-->
					<td width=70>Test Matrix Confirm</td><td width=20 style='background-color:gray;'><hr></td>
					<td width=70>Sample Status</td><td width=20 style='background-color:gray;'><hr></td>
					<td width=70>Test date confirm</td><td width=20 style='background-color:gray;'><hr></td>
					<td width=70>Test conduction & result</td><td width=20 style='background-color:gray;'><hr></td>
					<td width=70>After test</td>
				</tr>
			</table>
		</td>
		<td align="right">
		
		<table>
		<tr>
		<td style="padding-right:10px">
		<a href="#" onclick="logout()" style="color:white;font-size:20px;" class="trival-text">Logout</a></td>
		</tr>
		</table>
		</td>
	</tr>
	<tr valign="top">
		<td colspan=3 height=30 id="menuDiv"></td>
	</tr>
	<tr valign="top"><td colspan=3>

<script type="text/javascript">
var tb,advSearchWin,searchResultStore,comboSearchPanel,advSearchResultWindow,sysSettingWin,userWin = null,templateWin,templateGrid,templateMgtWin,templateMgtGrid,changePwdWin,changePwdForm;
function logout(){
	Ext.MessageBox.confirm('Confirm', 'Do you want to logout?', function(btn){
		if(btn == 'yes'){		
			document.location='userLogout.action';
		}
	});
}

function goList(){
	document.location='manageList.action';
}

function goUserManagement(){
	document.location='manageUser.action';
}

function doDelTemplate(orderId,templateName){
	Ext.MessageBox.confirm('Confirm', 'Do you want to delete the template['+templateName+']?', function(btn){
		if(btn == 'yes'){
			templateMgtGrid.getEl().mask('deleting...');
			Ext.Ajax.request({
				url: 'deleteOrder.action',
				params: {
					orderId:orderId
				},
				success: function(response){
					var result = Ext.util.JSON.decode(response.responseText);
					Ext.Msg.alert('Info', result.message);
					templateMgtGrid.getEl().unmask();
					templateMgtGrid.getStore().load();
					templateMgtGrid.getView().refresh();
				},
				failure: function(response){
					Ext.Msg.alert('Warning', response.responseText);
					templateMgtGrid.getEl().unmask();
				}
			});	
		}
	});
}

function doUpgrade(){
	Ext.Ajax.request({
		url: 'upgrade.action',
		success: function(response){
			var result = Ext.decode(response.responseText);
			if(result.state==0){
				Ext.MessageBox.alert('Info', 'upgrade successfully.');
			}else{
				Ext.MessageBox.alert('Info', result.message);
			}
		}
	});	
}

function goTemplateManagement(){
	if(!templateMgtWin){
		templateMgtGrid=Ext.create('Ext.grid.Panel',{
			columns: [{
				header: 'Template Name', 
				width: 260,
				dataIndex: 'templateName',
				editor: {
					xtype: 'textfield',
					allowBlank:false
				}
			},{
				header: 'Scope',
				dataIndex:'private',
				renderer: function(value,a,obj,idx){
					return value==false?"Public":"Private";
				},
				editor: {
					xtype: 'combo',
					editable:false,
					displayField: 'name',
					valueField: 'val',
					store: Ext.create('Ext.data.Store', {
						fields:['name','val'],
						data:[{"name":"Public","val":false},{"name":"Private","val":true}]
					})
				}
			},{
				xtype: 'gridcolumn',
				width: 40,
				renderer: function(value,a,obj,idx){
					var orderId = templateMgtGrid.getStore().getAt(idx).data.orderId;
					var templateName = templateMgtGrid.getStore().getAt(idx).data.templateName;
					return '<img title="Delete Templatae" src="images/delete.gif" onclick="doDelTemplate('+orderId+',\''+templateName+'\')"/>';
				}
			}],
			plugins: [Ext.create('Ext.grid.plugin.RowEditing', {
				clicksToMoveEditor: 2,
				errorSummary:false,
				autoCancel: false,
				listeners:{
					'edit':function(editor,e,eOpts ){
						var updates = templateMgtGrid.getStore().getUpdatedRecords();
						if(updates&&updates.length>0){
							var templateId = updates[0].data.templateId;
							var templateName = updates[0].data.templateName;
							var isPublic = !updates[0].data.private;
							Ext.Ajax.request({
								url: 'updateOrderTemplate.action',
								params: {
									templateId:templateId,
									templateName:templateName,
									isPublic:isPublic
								},
								success: function(response){
									var result = Ext.util.JSON.decode(response.responseText);
									Ext.Msg.alert('Info', result.message);
									templateMgtGrid.getEl().unmask();
									templateMgtGrid.getStore().load();
									templateMgtGrid.getView().refresh();
								},
								failure: function(response){
									Ext.Msg.alert('Warning', response.responseText);
									templateMgtGrid.getEl().unmask();
								}
							});
						}
					}
				}
			})],
			store:Ext.create('Ext.data.Store', {
				autoLoad:false,
				fields: [{name:'orderId'},{name:'templateName'},{name:'private'},{name:'templateId'}],
				proxy: {
					type: 'ajax',
					url: 'getOrderTemplates.action',
					extraParams:{category:0},
					reader: {
						type: 'json',
						root: 'items',
						totalProperty: 'size'
					}
				}			
			}),
			height:200,
			width:440,
			autoScroll:true,
			enableColumnHide:false,
			enableColumnMove:false
		});
		templateMgtWin=Ext.create('Ext.Window', {
			title: 'Template Management',
			border:0,
			modal:true,
			buttonAlign : "center",
			layout:'vbox',
			width:450,
			height:280,
			defaults: {
				anchor: '100%'
			},
			items: [{
				xtype:'label',
				text:'Double click to edit the template, click button \'X\' to delete from trp system.'
			},templateMgtGrid],
			closeAction: function(){
				templateMgtWin.hide();
			},
			buttonAlign:'center',
			buttons:[{
				text:'Close',
				handler:function(){
					templateMgtWin.hide();
				}
			}]
		});
	}
	templateMgtGrid.getStore().load();
	templateMgtWin.show();
}

function simpleSearch(text){
	Ext.Ajax.request({
		url: 'searchByNo.action',
		params: {
			orderNumber: text
		},
		success: function(response){
			var result = Ext.decode(response.responseText);
			if(result.orderId==-1){
				Ext.MessageBox.alert('Warning', 'No record found.');
			}else{
				document.location='viewOrder.action?orderId=' + result.orderId;
			}
		}
	});
}

function advSearch(){
	if(!advSearchWin){
		var advanceSearchForm = Ext.create('Ext.form.Panel', {
			frame: true,
			bodyStyle:'padding:5px 5px 0',
			forceFit:true,
			buttonAlign:'center',
			items: [{
				fieldLabel: 'Customer',
				name: 'customer',
				id: 'customer',
				xtype:'combo',
				editable:true,
				autoScroll:true,
				queryMode: 'local',
				displayField: 'name',
				valueField: 'name',
				store:  Ext.create('Ext.data.Store', {
					autoLoad:true,
					fields: ['name'],
					proxy: {
						type: 'ajax',
						url: 'getList.action?listId=1',
						reader: {
							type: 'json',
							root: 'itemList',
							totalProperty: 'size'
						}
					}
				})
			},
			{
				fieldLabel: 'Project',
				name: 'project',
				id: 'project',
				xtype: 'combo',
				editable:true,
				autoScroll:true,
				queryMode: 'local',
				displayField: 'name',
				valueField: 'name',
				store:  Ext.create('Ext.data.Store', {
					autoLoad:true,
					fields: ['name'],
					proxy: {
						type: 'ajax',
						url: 'getList.action?listId=2',
						reader: {
							type: 'json',
							root: 'itemList',
							totalProperty: 'size'
						}
					}
				})
			},
			{
				fieldLabel: 'Product',
				name: 'product',
				id: 'product',
				xtype: 'combo',
				editable:true,
				autoScroll:true,
				queryMode: 'local',
				displayField: 'name',
				valueField: 'name',
				store:  Ext.create('Ext.data.Store', {
					autoLoad:true,
					fields: ['name'],
					proxy: {
						type: 'ajax',
						url: 'getList.action?listId=3',
						reader: {
							type: 'json',
							root: 'itemList',
							totalProperty: 'size'
						}
					}
				})
			},
			{
				fieldLabel: 'Project Number',
				name: 'projNum',
				id: 'projNum',
				xtype: 'textfield'
			}],
			buttons: [{
				text: 'Submit',
				handler: function() {
					if(!advSearchResultWindow){
						searchResultStore = Ext.create('Ext.data.Store', {
							fields:['orderNumber','prjNumber', 'prjName', 'statusName', 'orderId'],
							autoLoad: false,
							pageSize: 20,
							proxy: {
								type: 'ajax',
								url: 'searchByMulti.action',  // url that will load data with respect to start and limit params
								reader: {
									type: 'json',
									root: 'items',
									totalProperty: 'size'
								}
							}
						});
						
						comboSearchPanel = Ext.create('Ext.grid.Panel', {
							forceFit: true,
							autoScroll:true,
							rowspan:2,
							columns: [{header: 'Order Number',  dataIndex: 'orderNumber', width: 150},
									  {header: 'Project Number',  dataIndex: 'prjNumber', width: 150},
									  {header: 'Project Name',  dataIndex: 'prjName', width: 150},
									  {header: 'Status',  dataIndex: 'statusName', width: 200},
									  {
											xtype: 'actioncolumn',
											width: 40,
											items: [{
												icon   : 'images/view.gif',
												tooltip: 'View Order',
												handler: function(grid, rowIndex, colIndex) {
													var orderId = comboSearchPanel.getStore().getAt(rowIndex).data.orderId;
													document.location='viewOrder.action?orderId='+orderId;
												}
											}]
										}
									  ],
							store: searchResultStore,
							bbar:new Ext.PagingToolbar({  
								store: searchResultStore,  
								displayInfo: true,
								prependButtons: true,  
								displayMsg : 'Record {0} ~ {1}, Total: {2}',     
								emptyMsg : "No Record",
								doLoad:function(start){  
								}  
							}),
							height: 250,
							width: 450
						});
						advSearchResultWindow = Ext.create('Ext.Window', {
							title: 'Order Search Results',
							border:0,
							layout: 'fit',
							items: [comboSearchPanel],
							closeAction: function(){
								advSearchResultWindow.hide();
							}
							
						});
					}	
					searchResultStore.loadPage(1,{params:{customerName:Ext.getCmp('customer').getValue(),projectName:Ext.getCmp('project').getValue(),
						productName:Ext.getCmp('product').getValue(),projectNum:Ext.getCmp('projNum').getValue()}});
					comboSearchPanel.getView().refresh();
					advSearchResultWindow.show();
					advSearchWin.hide();
				}
			},
			{
				text: 'Cancel',
				handler: function() {
					advanceSearchForm.getForm().reset();
					advSearchWin.hide();
				}
			}]
		});
		advSearchWin = Ext.create('Ext.Window', {
			title: 'Advanced Search',
			border:0,
			modal:true,
			buttonAlign : "center",
			defaultType: 'textfield',
			width:300,
			height:180,
			defaults: {
				anchor: '100%'
			},
			items: [advanceSearchForm],
			closeAction: function(){
				advSearchWin.hide();
			}
		});
	}
	advSearchWin.show();
}

function goSystemSetting(){
	if(!sysSettingWin){
		sysSettingWin = Ext.create('Ext.Window', {
			title: 'System Settings',
			width: 510,
			height: 300,
			autoScroll:true,
			border:0,
			modal:true,
			buttonAlign : "center",
			defaultType: 'textfield',
			defaults: {
				anchor: '100%'
			},
			items: Ext.create('Ext.form.Panel', {
					frame:true,
					id:'sForm',
					url: 'updateProperties.action',
					bodyStyle:'padding:5px 5px 0',
					border:0,
					defaultType: 'textfield',
					defaults: {
						anchor: '100%',
						iconAlign:'top',
						width:460,
						labelWidth:100
					},
					layout:{
						type:'table',
						columns:1,
						tableAttrs: {
							border:1,
							cellspacing:1,
							bordercolor:'white'
						}
					}
				}),	
			closeAction: function(){
				sysSettingWin.hide();
			},
			buttons:[{
				text:'Save',
				id:'btnSave1',
				handler: function(){
					Ext.getCmp('sForm').getForm().submit({
						success: function(form, action){
							sysSettingWin.mask('saving data...');
							var result = action.result;
							if(result.data.state==0){
								flashMessage('data saved.','btnSave1',1500);
							}else{
								Ext.MessageBox.alert('Warning', 'save failed,please try again later.');
							}
							sysSettingWin.getEl().unmask();
						},
						failure:function(form, action){
							Ext.MessageBox.alert('Warning', 'save failed,please try again later.');
							sysSettingWin.getEl().unmask();
						}
					});
				}
			},
			{
				text:'Cancel',
				handler: function(){
					sysSettingWin.hide();
				}
			}]
		});	
		Ext.Ajax.request({
			url: 'getProperties.action',
			success: function(response){
				var result = Ext.util.JSON.decode(response.responseText);
				var formPanel = Ext.getCmp('sForm');
				if(result.items.length>0){
					for(var i=0;i<result.items.length;i++){
						var prop = result.items[i];
						formPanel.add({
							inputId:'p_'+prop.id,
							fieldLabel:prop.name,
							value:prop.value
						});
					}
				}
			},
			failure: function(response){
			}
		});	
	}
	sysSettingWin.show();
}

function changePassword(){
	if(!changePwdWin){
		changePwdForm = Ext.create('Ext.form.Panel', {
			frame:true,
			bodyStyle:'padding:5px 5px 0',
			border:0,
			defaultType: 'textfield',
			defaults: {
				anchor: '100%',
				iconAlign:'top'
			},
			layout:{
				type:'table',
				columns:1
			},
			items:[{
				fieldLabel: 'Current password',
				id: 'oldPwd',
				inputType: 'password', 
				allowBlank:false
			},{
				fieldLabel: 'New password',
				id: 'newPwd',
				inputType: 'password', 
				allowBlank:false
			},{
				fieldLabel: 'Confirm new password',
				id: 'cfmNewPwd',
				inputType: 'password', 
				allowBlank:false
			}]
		});	
		changePwdWin = Ext.create('Ext.Window', {
			title: 'Change password',
			width: 300,
			height: 160,
			border:0,
			modal:true,
			buttonAlign : "center",
			defaults: {
				anchor: '100%'
			},
			items: changePwdForm,
			closeAction: function(){
				changePwdWin.hide();
			},
			buttons:[{
				text:'Change',
				id:'btnChangePwd',
				handler:function(){
					if(changePwdForm.getForm().isValid()){
						var oldPwd = Ext.getCmp('oldPwd').getValue();
						var pwd1 = Ext.getCmp('newPwd').getValue();
						var pwd2 = Ext.getCmp('cfmNewPwd').getValue();
						if(pwd1!=pwd2){
							Ext.Msg.alert('Warning', 'new password not match!');
						}else{
							changePwdWin.getEl().mask('processing...');
							Ext.Ajax.request({
								url: 'changePassword.action',
								params: {
									to:'<%=cUser.getEmail()%>',
									oldPwd:oldPwd,
									newPwd:pwd1,
									emailId:5
								},
								success: function(response){
									var result = Ext.util.JSON.decode(response.responseText);
									Ext.Msg.alert('Info', result.message);
									changePwdWin.getEl().unmask();
									if(result.state==0){
										changePwdWin.hide();
									}	
								},
								failure: function(response){
									Ext.Msg.alert('Warning', response.responseText);
									changePwdWin.getEl().unmask();
								}
							});
						}
					}else{
						Ext.Msg.alert('Warning', 'Please fill in all the required fields!');
					}
				}
			},{
				text:'Cancel',
				handler:function(){
					changePwdWin.hide();
				}
			}]
		});
	}
	changePwdForm.getForm().reset();
	changePwdWin.show();
}

function showEditProfile() {
	Ext.Ajax.request({
		url: 'getCurrentUser.action',

		success: function(response){
			var user = Ext.decode(response.responseText);
			var isSuper = false;
			if(user.roleList){
				for(var i=0;i<user.roleList.length;i++){
					if(user.roleList[i].roleId==2){
						isSuper = true;break;
					}
				}
			}
			if(userWin == null){
				
				var userForm = Ext.create('Ext.form.Panel', {
					frame:true,
					bodyStyle:'padding:5px 5px 0',
					border:0,
					defaultType: 'textfield',
					defaults: {
						anchor: '100%',
						iconAlign:'top'
					},
					layout:{
						type:'table',
						columns:1
					},
					items:[{
						fieldLabel: 'User Email',
						id: 'email',
						name: 'email',
						allowBlank:false,
						width:400
					},{
						fieldLabel: 'User Name',
						id: 'name',
						name: 'name',
						allowBlank:false,
						width:400
					},{
						fieldLabel: 'Division',
						name: 'division',
						id: 'division',
						allowBlank:false,
						width:400
					},{
						fieldLabel: 'Department',
						name: 'department',
						id: 'department',
						allowBlank:false,
						width:400
					},{
						fieldLabel: 'Position',
						name: 'position',
						id: 'position',
						xtype:'combo',
						width:400,
						allowBlank:false,
						displayField: 'name',
						valueField: 'name',
						typeAhead:true,
						autoScroll:true,
						queryMode: 'local',
						store:  Ext.create('Ext.data.Store', {
							autoLoad:true,
							fields: ['name'],
							proxy: {
								type: 'ajax',
								url: 'getList.action?listId=8',
								reader: {
									type: 'json',
									root: 'itemList',
									totalProperty: 'size'
								}
							}
						})
					},{
						fieldLabel: 'Desk Tel(Dir)',
						name: 'tel',
						id: 'tel',
						allowBlank:false,
						width:400
					},{
						fieldLabel: 'Mobile',
						name: 'mobile',
						id: 'mobile',
						allowBlank:false,
						width:400
					},{
						xtype:'checkbox',
						boxLabel: 'Super Admin',
						name: 'isAdmin',
						id: 'isAdmin',
						inputValue: 'Y',
						//readOnly:true,
						width:400
					},{
						xtype:'hidden',
						id:'userId'
					}]
				});
				
				userWin = Ext.create('Ext.Window', {
					title: 'User Profile',
					width: 510,
					height: 300,
					border:0,
					modal:true,
					buttonAlign : "center",
					defaultType: 'textfield',
					defaults: {
						anchor: '100%'
					},
					items: userForm,
					closeAction: function(){
						userWin.hide();
					},
					buttons:[{
						text:'Save',
						id:'btnSave2',
						handler:function(){
							if(!userForm.getForm().isValid()){
								Ext.MessageBox.alert('Warning','Please fill in all the fields!');
								return;
							}
							userWin.getEl().mask('saveing data...');
							userForm.getForm().submit({
								url: 'updateUser.action',
								params:{userId:Ext.getCmp('userId').getValue()},
								success: function(form, action){
									var result = action.result;
									if(result.data.state==0){
										flashMessage('data saved.','btnSave2',1500);
									}else{
										Ext.MessageBox.alert('Warning', 'save failed,please try again later.');
									}
									userWin.getEl().unmask();
								}
							});
						}
					},{
						text:'Cancel',
						handler:function(){
							userWin.hide();
						}
					}]
				});
			}
			Ext.getCmp('email').setValue(user.email);
			Ext.getCmp('name').setValue(user.name);
			Ext.getCmp('division').setValue(user.division);
			Ext.getCmp('department').setValue(user.department);
			Ext.getCmp('position').setValue(user.position);
			Ext.getCmp('tel').setValue(user.tel);
			Ext.getCmp('mobile').setValue(user.mobile);
			if(isSuper){
				Ext.getCmp('isAdmin').setValue('Y');
			}else{
				Ext.getCmp('isAdmin').setValue('');
				Ext.getCmp('isAdmin').setDisabled(true);
			}
			Ext.getCmp('userId').setValue(user.userId);
			userWin.show();
		}		
	});
}

//Ext.Loader.setConfig({enabled: true});
//Ext.Loader.setPath('Ext.ux', 'js/ux');
Ext.require([
   	'Ext.form.*',
   	'Ext.layout.container.Column',
    'Ext.menu.*',
   	'Ext.tab.Panel',
	'Ext.window.MessageBox',
	'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.state.*',
    'Ext.tip.*'
]);
Ext.QuickTips.init();
Ext.Ajax.timeout=180000;
Ext.Ajax.defaultPostHeader += ";charset=utf-8"; 


Ext.override(Ext.form.Action.Submit,{  
    // private  
    processResponse : function(response){  
        this.response = response;  
  
        ////////////////////////  
        var data = response.responseText;  
        if(data.indexOf('<pre>') != -1) {  
          response.responseText = data.substring(5, data.length-6);  
          this.response = Ext.util.JSON.decode(response.responseText);  
        }
		if(data.indexOf('<pre') !=-1){
			var idx = data.indexOf('>');
			response.responseText = data.substring(idx+1, data.length-6);  
		}
        ///////////////////////////       
        if(!response.responseText){  
            return true;  
        }  
        this.result = this.handleResponse(response);  
        return this.result;  
    }  
});

if(!tb){
	tb=Ext.create('Ext.toolbar.Toolbar', {
		renderTo: 'menuDiv',
		autoWidth:true,
		height:40,
		layout: {
            type: 'table',
            rows: 1
        },
		suspendLayout:false,
		padding:3,
		items: [{
			text: 'Home',
			width:70,
			handler: function(){
				document.location='userProfile.action';
			}
		},{
			text: 'My Profile',
			width:100,
			menu:{
				items:[{
					text:'Modify my profile',
					handler: showEditProfile
				},{
					text:'Change password',
					handler:changePassword
				}]
			}
		},{
			text: 'New request',
			width:120,
			menu:{
				items:[{
					text:'Start a new request',
					handler:function(){
						document.location='modelChoose.action?action=new';
					}
				},{
					text: 'Start a new request from template',
					handler:function(){
						if(!templateWin){
							templateGrid=Ext.create('Ext.form.Panel',{
								frame: true,
								bodyStyle:'padding:5px 5px 0',
								forceFit:true,
								border:0,
								layout:'vbox',
								items: [{
									fieldLabel: 'Public',
									name: 'comboPublicTemp',
									id: 'comboPublicTemp',
									displayField: 'templateName',
									valueField: 'orderId',
									editable:false,
									xtype:'combo',
									queryMode: 'local',
									store:Ext.create('Ext.data.Store', {
										autoLoad:false,
										fields: [{name:'orderId'},{name:'templateName'},{name:'private'}],
										proxy: {
											type: 'ajax',
											url: 'getOrderTemplates.action',
											extraParams:{category:1},
											reader: {
												type: 'json',
												root: 'items',
												totalProperty: 'size'
											}
										}			
									}),
									listeners:{
										'change':function(field,newValue,oldValue,opts){
											if(newValue!=''){
												Ext.getCmp('comboPrivateTemp').setValue('');
											}
										}
									},
									width: 300
								},
								{
									fieldLabel: 'Private',
									name: 'comboPrivateTemp',
									id: 'comboPrivateTemp',
									displayField: 'templateName',
									valueField: 'orderId',
									editable:false,
									xtype:'combo',
									queryMode: 'local',
									store:Ext.create('Ext.data.Store', {
										autoLoad:false,
										fields: [{name:'orderId'},{name:'templateName'},{name:'private'}],
										proxy: {
											type: 'ajax',
											url: 'getOrderTemplates.action',
											extraParams:{category:2},
											reader: {
												type: 'json',
												root: 'items',
												totalProperty: 'size'
											}
										}			
									}),
									listeners:{
										'change':function(field,newValue,oldValue,opts){
											if(newValue!=''){
												Ext.getCmp('comboPublicTemp').setValue('');
											}
										}
									},
									width: 300
								}]
							});
							templateWin=Ext.create('Ext.Window', {
								title: 'Request Template List',
								border:0,
								modal:true,
								buttonAlign : "center",
								width:400,
								height:130,
								defaults: {
									anchor: '100%'
								},
								items: [templateGrid],
								buttonAlign:'center',
								buttons: [{
									text: 'Go',
									id:'btnGo',
									handler: function() {
										var val1=Ext.getCmp('comboPublicTemp').getValue();
										var val2=Ext.getCmp('comboPrivateTemp').getValue();
										var orderId;
										if(val1!=''&&val1!=null){
											orderId = val1;
										}else if(val2!=''&&val2!=null){
											orderId = val2;
										}else{
											Ext.MessageBox.alert('Warning', 'Please select one Template.');
											return;
										}
										document.location='createOrderFromTemplate.action?orderId='+orderId;
									}
								},
								{
									text: 'Close',
									handler: function() {
										templateGrid.getForm().reset();
										templateWin.hide();
									}
								}],
								closeAction: function(){
									templateWin.hide();
								}
							});
						}
						Ext.getCmp('comboPublicTemp').getStore().load();
						Ext.getCmp('comboPrivateTemp').getStore().load();
						templateWin.show();
					}
				}]
			}
		}
		<%if("Test Engineer".equals(cUser.getPosition())||"V&V Engineer".equals(cUser.getPosition())||"Manager".equals(cUser.getPosition())){%>
		,{
			text: 'General Actions',
			width: 120,
			forceFit:true,
			menu:{
				items:[
				{
					text: 'Pipeline',
					handler:function(){
						document.location='viewPipeline.action';
					}
				},{
					text: 'View lab schedule',
					handler:function(){
						document.location='viewLabSchedule.action';
					}
				}
				]	
			}
		}
		<%}%>
		,{
			text: 'Admin Management',
			width:170,
			forceFit:true,                                                                                                             
			menu : {
				items: [{
						text:'Template Management',
						handler:goTemplateManagement
					}
		<%if("test@trw.com".equals(cUser.getEmail())){%>		
		,{
			text:'Upgrade',
			handler:doUpgrade
		}
		<%}%>
		<%if("Test Engineer".equals(cUser.getPosition())||"V&V Engineer".equals(cUser.getPosition())||"Manager".equals(cUser.getPosition())){%>
					,{
						text: 'List Configuration',
						handler:goList
					},{
						text: 'User Management',
						handler:goUserManagement
					},{
						text: 'System Settings',
						handler:goSystemSetting
					}
		<%}%>
				]
			}
		}
		,{
			xtype:'tbspacer',
			width: 90
		},{
			xtype:'textfield',
			fieldLabel:'<span style="font-size:13;padding-top:3px;">Request No</span>',
			labelAlign:'right',
			height:25,
			id:'orderNum',
			labelWidth:80,
			width:180
		},{
			xtype:'button',
			text: 'Search',
			width:60,
			handler: function() {
        		simpleSearch(Ext.getCmp('orderNum').value);
        	}
		},{
			xtype:'button',
			text: 'Adv Search>>',
			width:100,
			handler: advSearch
		}]
	});
}	
</script>